# -*- coding: utf-8 -*-
import maya.cmds as cmds
import maya.mel as mel
import os , sys
import importlib

def import_and_run_arg(class_name):
    module = importlib.import_module(class_name)
    # 调用模块中的函数
    class_obj = getattr(module, class_name)
    instance = class_obj ()
    method = getattr ( instance , class_name )
    return(method ())
def import_and_run (  class_name , method_name='' ) :
    module = importlib.import_module ( class_name )
    # 获取并实例化模块中的类
    cls = getattr ( module , class_name )
    if callable ( cls ) :
        instance = cls ( )
        if method_name :
            # 如果提供了方法名，调用该方法
            method = getattr ( instance , class_name )
            if callable ( method ) :
                return(method ( method_name))
        else :
            # 如果没有提供方法名，直接执行实例
            return(instance())

class QL_batch_Check ( ) :
    def QL_batch_Check ( self ,path,content,publishPath) :
        Check_Log = ''
        current_file_pathlist = [ ]
        current_file_path = path
        self.current_file_directory = content
        Flie_Name = current_file_path.split ( '/' ) [ -1 ].split ( '.' ) [ 0 ]
        cmds.file ( current_file_path , o = 1 , f = 1 )
        current_file_pathlist.append ( self.current_file_directory )
        print ("77777777777777777777777777")
        if current_file_pathlist :
            file_folder = os.path.join ( self.current_file_directory , "Scence" ).replace ( "\\" , "/" )
            if not os.path.exists ( file_folder ) :
                os.mkdir ( file_folder )

            self.folder_path = os.path.join ( self.current_file_directory , "log" ).replace ( "\\" , "/" )
            if not os.path.exists ( self.folder_path ) :
                os.mkdir ( self.folder_path )

            camAbc_folder_path = os.path.join ( self.current_file_directory , "Cam_abc" ).replace ( "\\" , "/" )
            if not os.path.exists ( camAbc_folder_path ) :
                os.mkdir ( camAbc_folder_path )

            camFbx_folder_path = os.path.join ( self.current_file_directory , "Cam_fbx" ).replace ( "\\" , "/" )
            if not os.path.exists ( camFbx_folder_path ) :
                os.mkdir ( camFbx_folder_path )

            Mov_folder_path = os.path.join ( self.current_file_directory , "Mov" ).replace ( "\\" , "/" )
            if not os.path.exists ( Mov_folder_path ) :
                os.mkdir ( Mov_folder_path )

            # 使用 filter() 函数清除空项
            filtered_list = list ( filter ( lambda x : x.strip ( ) , publishPath.split(',') ) )
            Check_Log += Flie_Name + "\n"
            print ("8888888888888888888888888888888888888888888888888888")
            # 打印清除空项后的列表
            for index1  in filtered_list :
                if index1 == "Check_UnknownNode":
                    Check_Log += "," + index1 + "," + str (  import_and_run_arg ( index1) ) + "\n"
                    print (index1 + str ( "通过"))
                elif index1 == "Check_Starfram":
                    Check_Log += "," + index1 + "," + str ( import_and_run_arg ( index1 ) ) + "\n"
                    print (index1 + str ( "通过"))
                elif index1 == "Check_MultipleNamespace":
                    Check_Log += "," + index1 + "," + str ( import_and_run_arg ( index1 ) ) + "\n"
                    print (index1 + str ( "通过"))
                elif index1 == "Check_Namespace":
                    Check_Log += "," + index1 + "," + str ( import_and_run_arg ( index1 ) ) + "\n"
                    print (index1 + str ( "通过"))
                elif index1 == "Check_CamName":
                    Check_Log += "," + index1 + "," + str ( import_and_run_arg ( index1 ) ) + "\n"
                    print (index1 + str ( "通过"))
                elif index1 == "Check_Export_Cam_ABC":
                    Check_Log += "," + index1 + "," + str ( import_and_run ( index1 , method_name = camAbc_folder_path ) ) + "\n"
                    print (index1 + str ( "通过"))
                elif index1 == "Check_Export_Cam_FBX":
                    Check_Log += "," + index1 + "," + str ( import_and_run ( index1 , method_name = camFbx_folder_path ) ) + "\n"
                    print (index1 + str ( "通过"))
                elif index1 == "Check_isLook_Cam":
                    Check_Log += "," + index1 + "," + str ( import_and_run_arg ( index1 ) ) + "\n"
                    print (index1 + str ( "通过"))
                elif index1 == "Check_isRefLoaded":
                    Check_Log += "," + index1 + "," + str (  import_and_run_arg ( index1 ) ) + "\n"
                    print (index1 + str ( "通过"))
                elif index1 == "Check_MergeAnim_layers":
                    Check_Log += "," + index1 + "," + str ( import_and_run_arg ( index1 ) ) + "\n"
                    print (index1 + str ( "通过"))
                elif index1 == "Check_TPose":
                    Check_Log += "," + index1 + "," + str ( import_and_run ( index1 , method_name = 'Chr') ) + "\n"
                    print (index1 + str ( "通过"))
                elif index1 == "Check_Playblast":
                    Check_Log += "," + index1 + "," + str ( import_and_run ( index1 , method_name =Mov_folder_path) ) + "\n"
                    print (index1 + str ( "通过"))
            try :
                # 使用cmds.file命令保存为.ma格式文件
                cmds.file ( rename = os.path.join ( file_folder , Flie_Name + '.ma' ) )
                cmds.file ( save = True , type = 'mayaAscii' )
                Check_Log += ",另存文件," + str ( "保存成功-YES" ) + "\n"
            except :
                Check_Log += ",另存文件," + str ( "保存失败-NO" ) + "\n"
            Flie_Path = self.folder_path + "/log.txt"
            print("9999999999999999999999999999")
            with open ( Flie_Path , 'a' ) as f :
                for line in Check_Log.splitlines ( ) :
                    f.write ( line + "\n" )
        else :
            return (u"File name read failure!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")


#QL_batch_Check ( ).QL_batch_Check ( )
